package com.atguigu.serviceedu.controller;


import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.service.EduSubjectService;
import com.atguigu.serviceedu.vo.OneLevelSubject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author wyj
 * @since 2021-12-18
 */
@RestController
@RequestMapping("/serviceedu/subject")
//@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        //返回错误提示信息
        subjectService.importSubjectData(file,subjectService);
        //判断返回集合是否为空
        return R.ok();
    }
    //查询所有课程
    @ApiOperation(value = "所有课程查询")
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneLevelSubject> list = subjectService.selectAllSubject();
        return R.ok().data("list",list);
    }
}

